<template>
  <div class="icons-container">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icons" v-for="item in page" :key="item.id">
          <div class="icons-img">
            <img class="img-content" :src="item.imgUrl">
          </div>
            <p class="icons-desc">{{ item.desc }}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

export default {
  name: 'homeIcons',
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconsList.forEach((item,index) => {
        const page =  Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  props: {
    iconsList : {
      type: Array,
      default: () => []
    }
  }
}
</script>

<style lang ="scss" scoped>
.icons-container /deep/ .swiper-container  {
  height: 0;
  padding-bottom: 50%;
}
.icons-container {
  margin-top: .1rem;
  .icons {
    overflow: hidden;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    float: left;
    position: relative;
    .icons-img {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      box-sizing: border-box;
      padding: .1rem;
      bottom: .44rem;
      .img-content {
        display: block;
        margin: 0 auto;
        height: 100%;
      }
    }
    .icons-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: .44rem;
      line-height: .44rem;
      color: $dartTextColor;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      }
    }
  }
</style>
